'use strict';

const Service = require('egg').Service;

class UserService extends Service {
  async login() {
    // const { app } = this;

    // const user = await this.app.mysql.query('select * from user where id = 1', '');


    this.app.mysql.update('user', { userName: 'wfy', id: 1 });
    const result = await this.app.mysql.select('user', {
      columns: [ 'id', 'userName' ], // 查询字段，全部查询则不写，相当于查询*
      where: {
        userName: 'wfy',
      }, // 查询条件
      orders: [
        [ 'id' ], // 降序desc，升序asc
      ],
      limit: 10, // 查询条数
      offset: 0, // 数据偏移量（分页查询使用）
    });
    return result;
    // const pool = app.pg
    // const querySQL = 'SELECT * from user'
    // try {
    //   const { rows } = await pool.query(querySQL)
    //   console.log(rows, 'rows')
    //   this.ctx.logger.debug('debug info from service');
    //   return rows;
    // } catch (e) {
    //   return '查询出差出错了';
    // }
  }
}

module.exports = UserService;
